package cn.blnp.net.flowable.boot.service.impl;

import cn.blnp.net.flowable.boot.ext.cmd.InjectUserTaskInProcessInstanceCmd;
import cn.blnp.net.flowable.boot.service.InjectUserTaskInProcessInstanceService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.ManagementService;
import org.flowable.engine.impl.dynamic.DynamicUserTaskBuilder;
import org.springframework.stereotype.Service;

/**
 * <h3>动态增加临时节点接口实现</h3>
 *
 * @author <a href="mailto:blnp.yibin@qq.com">lyb</a>
 * @version 1.0
 * @since 2025/6/19 15:58
 */
@Slf4j
@Service
@AllArgsConstructor
public class InjectUserTaskInProcessInstanceServiceImpl implements InjectUserTaskInProcessInstanceService {

    protected ManagementService managementService;


    @Override
    public void executeInjectUserTaskInProcessInstance(String currentTaskId, String newTaskKey, String newTaskName, String newTaskAssignee) {
        //初始化DynamicUserTaskBuilder
        DynamicUserTaskBuilder dynamicBuilder = new DynamicUserTaskBuilder();
        dynamicBuilder.setId(newTaskKey);
        dynamicBuilder.setName(newTaskName);
        dynamicBuilder.setAssignee(newTaskAssignee);
        //初始化Command类
        InjectUserTaskInProcessInstanceCmd injectUserTaskInProcessInstanceCmd = new InjectUserTaskInProcessInstanceCmd(currentTaskId, dynamicBuilder);
        //通过ManagementService管理服务执行动态增加临时节点Command类
        managementService.executeCommand(injectUserTaskInProcessInstanceCmd);
    }
}
